const express = require("express");
const router = express.Router();
const setGoodsHandler = require("../router_handler/setGoods");
const expressJoi = require("@escook/express-joi");
const { add_goods_schema } = require("../schema/setGoods")
const path = require("path");
const uuid = require("uuid");

const multer = require("multer");
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, "../assets"));
  },
  filename: function (req, file, cb) {
    let urlArr = file.originalname.split(".");
    cb(null, file.fieldname + "_" + uuid.v4() + '.' + urlArr[urlArr.length - 1]);
  }
});
const upload = multer({ storage: storage });


// 添加商品路由
router.post("/addGoods", upload.single("image"), expressJoi(add_goods_schema), setGoodsHandler.addGoods);

module.exports = router;